package com.cljz.makepassenger.widget;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.MotionEvent;

import com.zhy.autolayout.AutoLinearLayout;

/**
 * Created by apple on 2017/4/24.
 */

public class FatherLinearLayout extends AutoLinearLayout {
    int mx = 0, my = 0;
    int lastx, lasty;
    private int downX;
    private int downY;
    private int xDown;
    private int xMove;

    public FatherLinearLayout(Context context) {
        this(context, null);
    }

    public FatherLinearLayout(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public FatherLinearLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }


    //    public boolean onInterceptTouchEvent(MotionEvent ev) {
//        Boolean intercept = false;
//        MotionEvent event = null;
//        //获取坐标点：
//        int x = (int) ev.getX();
//        int y = (int) ev.getY();
//        switch (ev.getAction()) {
//            case MotionEvent.ACTION_DOWN:
//                event = ev;
//                downX = (int) ev.getX();
//                downY = (int) ev.getY();
//                intercept = super.onInterceptTouchEvent(ev);
//                break;
//            case MotionEvent.ACTION_MOVE:
//                int deletx = x - mx;
//                int delety = y - my;
//                if (Math.abs(deletx) > Math.abs(delety)) {
//                    intercept = true;
//                } else {
//                    intercept = false;
//                }
//                break;
//            case MotionEvent.ACTION_UP:
//                if (Math.abs(ev.getX() - downX) > 15 || Math.abs(ev.getY() - downY) > 15) {
//                    intercept = true;
//                } else {
//                    intercept = false;
//                    ev.setAction(MotionEvent.ACTION_DOWN);
//                    dispatchTouchEvent(event);
//                }
//                break;
//            default:
//                break;
//        }
//        //这里尤其重要，解决了拦截MOVE事件却没有拦截DOWN事件没有坐标的问题
//        lastx = x;
//        lasty = y;
//        mx = x;
//        my = y;
//        L.e(intercept + "");
//        return_1 intercept;
//    }
//
//    //子view的代码·
//    public boolean dispatchTouchEvent(MotionEvent ev) {
//        int x = (int) ev.getX();
//        switch (ev.getAction()) {
//            case MotionEvent.ACTION_DOWN:
//                getParent().requestDisallowInterceptTouchEvent(true);
//                xDown = x;
//                break;
//            case MotionEvent.ACTION_MOVE:
//                xMove = x;
//                if (Math.abs(xMove - xDown) > 0) {    //根据业务需求判断是否需要通知父viewgroup来拦截处理该事件
//                    //允许父View进行事件拦截
//                    getParent().requestDisallowInterceptTouchEvent(false);
//                }
//                break;
//            case MotionEvent.ACTION_UP:
//                break;
//        }
//        return_1 super.dispatchTouchEvent(ev);
//    }


    //父viewgroup代码     (要确保down是不拦截，move和up时要拦截)
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
            return false;
        } else {
            return true;
        }
    }

}


